<?php
/**
 * created by zzy
 * date: 2018/1/26 14:07
 */


namespace App\Http\Admin\Logistics\Controllers;

use App\Eloquent\Ygt\LogisticsInvoice;
use Framework\BaseClass\Http\Admin\Controller;

class InvoiceController extends Controller
{
    public function index(){}
    public function lists()
    {
        $adminUser          = request()->user('admin')->toArray();
        $companyId          = $adminUser['company_id'];
        $notesId            = request('notes_id',0);
        if (request()->isMethod('post')) {

            $pageSize       = request('pageSize', 30);
            $pageCurrent    = request('pageCurrent', 1);
            $offset         = ($pageCurrent - 1) * $pageSize;

            $where          = ['notes_id'=>$notesId];
            $lists          = LogisticsInvoice::getList($where,'',$pageSize,$offset)->toArray();
            $count          = LogisticsInvoice::getCount($where);
            $data           = ['totalRow'=>$count,'pageCurrent'=>$pageCurrent,'list'=>$lists];
            $result         = json_encode($data);
            return $result;
        } else {
            return $this->view('lists',compact('notesId'));
        }
    }
    public function edit()
    {
        $adminUser          = request()->user('admin')->toArray();
        $companyId          = $adminUser['company_id'];

        $isSubmit           = request('is_submit',0);
        $notesId            = request('notes_id',0);
        if($isSubmit){
            $data                   = request()->all();
            //$data['company_id']   = $companyId;
            $fieldList              = LogisticsInvoice::$tableFieldList;
            $tableData              = LogisticsInvoice::setDataByTableField($data,$fieldList);
            $tableDataCheckResult   = LogisticsInvoice::checkDataByTableField($tableData,$fieldList);
            if($tableDataCheckResult !== true)
            {
                return $this->ajaxFail( $tableDataCheckResult );
            }
            $editResult             = LogisticsInvoice::edit($tableData);
            if( $editResult ){
                return $this->ajaxSuccess( '成功' );
            } else {
                return $this->ajaxFail( '失败' );
            }
        } else {
            return $this->view('edit',compact('notesId'));
        }
    }
    public function delete(){}
}